/**
  ******************************************************************************
  * @file     SD93F115B_exti.c
  * @author   TEST TEAM 												    	
  * @version  v0															    	
  * @date     Septemper 2022												    	
  * @brief  
  *           
  * Copyright (C) 2022  Hangzhou SDIC Microelectronics Co., Ltd
  ******************************************************************************/

/* Includes */
    
#include "SD93F115B_exti.h"
#include "SD93F115B_rcc.h"

 /**
  * @brief  Initializes the EXINT peripheral according to the specified
  *         parameters in the EXINT_InitStruct.
  * @param  EXINT_InitStruct: pointer to a EXINT_InitTypeDef structure that 
  *         contains the configuration information for the EXINT peripheral.
  * @retval None
  */

/*---------------------------------------------
 * 函数功能：外部中断相关寄存器恢复成上电默认值
 * 入口参数：
 * 出口参数：
 * 返回值  ：
 * 编写日期：
 * 作者    ：
 *---------------------------------------------*/
void EXINT_DeInit(void)
{
	RCC_APBPeriphResetCmd(RCC_APBPeriph_INT_KEY, ENABLE);
    RCC_APBPeriphResetCmd(RCC_APBPeriph_INT_KEY, DISABLE);
}

/*----------------------------------------
 * 函数功能：外部中断沿设置和使能
 * 入口参数：EXINT_INTx,EXINT_Trigger,NewState
 *           EXINT_INTx: where x can be (1,2) to select the EXINT peripheral
 * 			 EXINT_Trigger: EXINT_Trigger_Falling;EXINT_Trigger_Rising;EXINT_Trigger_Rising_Falling
 *           NewState: ENABLE;DISABLE
 * 出口参数：None
 * 返回值  ：None
 * 编写日期：
 * 作者    ：
 *----------------------------------------*/ 
void EXINT_EXITCmd(uint16_t EXINT_INTx, uint16_t EXINT_Trigger,FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_EXINT_Channel(EXINT_INTx));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
	assert_param(IS_EXINT_TRIGGER(EXINT_Trigger));
	
	if(EXINT_INTx==EXINT_INT0)
		EXINT->CR|=EXINT_Trigger;	
	else
		EXINT->CR|=(EXINT_Trigger<<2);
	
	if (NewState == ENABLE)
	{	
		EXINT->CR|=EXINT_INTx;							
	} 
	else 
	{
		EXINT->CR &=~EXINT_INTx;		
	}	
	
}

/*----------------------------------------
 * 函数功能：按键中断使能
 * 入口参数：EXINT_KEYx,NewState
 *           EXINT_KEYx: where x can be (0..6) to select the KEY peripheral
 *           NewState: ENABLE;DISABLE
 * 出口参数：None
 * 返回值  ：None
 * 编写日期：
 * 作者    ：
 *----------------------------------------*/
void EXINT_KeyCmd(uint16_t EXINT_KEYx, FunctionalState NewState)
{
	/* Check the parameters */
	assert_param(IS_EXINT_Channel(EXINT_KEYx));
    assert_param(IS_FUNCTIONAL_STATE(NewState));
	
	if (NewState == ENABLE)
	{	
		EXINT->CR|=EXINT_KEYx;
        EXINT->CR|=EXINT_KEY; 							
	} 
	else 
	{
		EXINT->CR &=~EXINT_KEYx;
        EXINT->CR &=~EXINT_KEY;		
	}
	
}

/*----------------------------------------
 * 函数功能：获取外部中断或按键中断标志位
 * 入口参数：EXINT_Channel
 * 出口参数：None
 * 返回值  ：None
 * 编写日期：
 * 作者    ：
 *----------------------------------------*/
ITStatus EXINT_GetEXITStatus(uint16_t EXINT_Channel)
{
	ITStatus bitstatus = RESET;
	
	/* Check the parameters */
	assert_param(IS_EXINT_Channel(EXINT_Channel));

	if ((EXINT->SR & EXINT_Channel) != RESET)
	{
		bitstatus = SET;
	}
	else
	{
		bitstatus = RESET;
	}
	return bitstatus;
}

/*----------------------------------------
 * 函数功能：清除外部中断或按键中断标志位
 * 入口参数：EXINT_Channel
 * 出口参数：None
 * 返回值  ：None
 * 编写日期：
 * 作者    ：
 *----------------------------------------*/
void EXINT_ClearEXITStatus(uint16_t EXINT_Channel)
{
	/* Check the parameters */
    assert_param(IS_EXINT_Channel(EXINT_Channel));
	
	EXINT->SR|=EXINT_Channel;
}

/****************************END OF FILE****************************/











